#include "LinkList.h"
#include <iostream>

using namespace std;

template <class T>
LinkList<T>::LinkList()
{
    this->head = new Node<T>();
    this->head->next = nullptr;
    this->length = 0;
}

template <class T>
LinkList<T>::LinkList(const LinkList<T> &linklist)
{
}

template <class T>
void LinkList<T>::creatList(const int &n)
{
    if (length == 0)
    {
        for (int i = 0; i < n; i++)
        {
            cout << "输入第" << i + 1 << "个元素:" << endl;
            T inData;
            cin >> inData;
            this->rearInsert(inData);
            this->length++;
        }
    }
    else{
        cout << "Error: LinkList is not empty" << endl;
    }
}

template <class T>
void LinkList<T>::rearInsert(const T &data)
{
    Node<T> *p = new Node<T>();
    p->data = data;
    p->next = nullptr;
    Node<T> cur = head;
    while (cur->next != nullptr)
    {
        cur = cur->next;
    }
    cur->next = p;

    this->length++
}

template <class T>
LinkList<T>::~LinkList()
{
}